package com.tianhui.consignortwofei.mvp.ui.activity.hetong;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonResponse;
import com.fgs.common.CommonView;
import com.fgs.common.pictureSelector.GlideEngine;
import com.fgs.common.progress.ExceptionHandle;
import com.fgs.common.progress.ObserverResponseListener;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.entity.LocalMedia;

import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.base.BaseActivity;
import com.tianhui.consignortwofei.base.BaseFragment;
import com.tianhui.consignortwofei.constant.Config;
import com.tianhui.consignortwofei.constant.KeyValue;
import com.tianhui.consignortwofei.mvp.model.UserInfoModel;
import com.tianhui.consignortwofei.mvp.model.hetong.ContractInfo;
import com.tianhui.consignortwofei.mvp.model.hetong.LiuChengListBean;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.adapter.LiuChengShowListAdapter;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.inter.OnItemChildClickListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * @author fgs
 * @date 2020/4/28
 * @description
 **/
public class LiuChengJieDianActivity extends BaseActivity {

    @BindView(R.id.rl_liucheng)
    RecyclerView rl_liucheng;

    private String contractno="";
    private UserInfoModel driverModel;
    protected RecyclerArrayAdapter mAdapter;
    private ContractInfo mContractInfo;

    @Override
    public int getLayoutId() {
        return R.layout.activity_liucheng_jiedian
                ;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }

    @Override
    public void init() {
        setTitle("流程显示");

        driverModel = new UserInfoModel();

        Bundle bundle = getIntent().getExtras();
        if (bundle != null && !bundle.isEmpty()) {
            mContractInfo = bundle.getParcelable(KeyValue.KEY_CONTRACT_INFO);
            contractno =mContractInfo.contractno;

        }
//        Bundle bundle = getIntent().getExtras();
//        if (bundle != null && !bundle.isEmpty()) {
//            contractno = bundle.getString("contractno");
//
//        }

        initAdapter();
        getLiuChengList();


    }

    private void initAdapter() {

        mAdapter= new LiuChengShowListAdapter(getContext());
        mAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(View view, int position) {
                LiuChengListBean list  = (LiuChengListBean)mAdapter.getAllData().get(position);

                List<LocalMedia> selectList =new ArrayList<>();
                LocalMedia media=new LocalMedia();
                media.setFileName("internet");
                media.setPath(Config.baseImageUrlTwo+list.getImgattachment());
//                    media.setCutPath(quotationListDTO.getPicture());
                selectList.add(media);
                // 预览图片 可自定长按保存路径
                PictureSelector.create(LiuChengJieDianActivity.this)
                        .themeStyle(com.fgs.common.R.style.picture_default_style) // xml设置主题
                        .setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)// 设置相册Activity方向，不设置默认使用系统
                        .isNotPreviewDownload(true)// 预览图片长按是否可以下载
                        .imageEngine(GlideEngine.createGlideEngine())// 外部传入图片加载引擎，必传项
                        .openExternalPreview(0, selectList);


            }
        });

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rl_liucheng.setLayoutManager(linearLayoutManager);
        rl_liucheng.setAdapter(mAdapter);
    }


    @Override
    public BaseFragment createFragment() {
        return null;
    }

//    @OnClick(R.id.activity_about_versionUpdateSettingItemView)
//    public void versionUpdate() {
//        updateCheck();
//    }

    private void getLiuChengList() {
        Map<String, String> map = new HashMap<>();
        map.put("contractno",contractno);
        driverModel.getLiuChengList(this, map, true, this.bindLifecycle(),
                new ObserverResponseListener<CommonResponse<List<LiuChengListBean>>>() {
                    @Override
                    public void onNext(CommonResponse<List<LiuChengListBean>> commonResponse) {
                        if (!isFinishing() && !isDestroyed()) {
                            if (commonResponse.getCode() == 20000) {
                                List<LiuChengListBean> list = commonResponse.getData();
                                if (list != null && list.size() > 0) {
//                                    getLeiXingType(list);
                                    mAdapter.addAll(list);
                                } else {
                                    showToast("未获取到列表信息");
                                }
                            } else {
                                showToast(commonResponse.getMsg());
                            }
                        }
                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseThrowable e) {

                        showToast(e.message);
                    }
                });
    }




}
